<?php
# file that contain functions to work with database

# function that will provide all information to connect to database.
function c_db_connect(){
	$g_db_server = $GLOBALS['g_db_server'];
	$g_db_user = $GLOBALS['g_db_user'];
	$g_db_pass = $GLOBALS['g_db_pass'];
	$g_db_name = $GLOBALS['g_db_name'];
	
	$link = mysql_connect($g_db_server, $g_db_user, $g_db_pass);
	if( !$link ){
		die('Could not connect: '.mysql_error());
	}
	
	$db_selected = mysql_select_db($g_db_name, $link);
	if (!$db_selected) {
		die ('Can\'t select database: ' . mysql_error());
	}
	
	$GLOBALS['g_db_link'] = $link;
} // c_db_connect()

# function to disconnect from database
function c_db_disconnect(){
	mysql_close($GLOBALS['g_db_link']);
} // c_db_disconnect()

# make query to database
# paramenters:
# * $query - query text
function c_db_query($query){
	$result = mysql_query($query, $GLOBALS['g_db_link']);
	return $result;
} // c_db_query()
?>